<template>
  <el-dialog :title="titleText" :visible.sync="showDialog" width="90%" top="0" :close-on-click-modal="false" class="equip-stading-book-choose" @close="cancel">
    <div class="list-wrapper">
      <EquipStadingBook ref="equipStadingBook" :type="type" @changeSelect="changeSelect" />
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button class="cancelbtn" @click="cancel">取 消</el-button>
      <el-button :loading="loading" :disabled="selectItems.length === 0" type="primary" class="savebtn" @click="sub">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ChooseDialog',
  components: {
    EquipStadingBook: () => import('../index.vue')
  },
  props: {
    value: Boolean,
    titleText: {
      type: String,
      default: '导入'
    },
    type: {
      type: Number,
      default: 2
    }
  },
  data() {
    return {
      showDialog: false,
      selectItems: [],
      loading: false
    };
  },

  watch: {
    value(v) {
      this.showDialog = v;
      if (!v) {
        this.reset();
      }
    }
  },
  created() {
    this.showDialog = this.value;
  },
  mounted() {},
  methods: {
    changeSelect(v) {
      this.selectItems = v;
    },
    close() {
      this.$emit('input', false);
    },
    cancel() {
      this.$emit('input', false);
    },
    reset() {
      this.loading = false;
      this.selectItems = [];
      this.$refs.equipStadingBook.clearSelect();
    },
    sub() {
      this.loading = true;
      this.$emit('sub', JSON.parse(JSON.stringify(this.selectItems)));
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__wrapper .el-dialog .el-dialog__body .el-form .el-form-item .el-form-item__label {
  min-width: 160px !important;
}
::v-deep {
  .el-divider__text {
    background-color: #f0f3f7;
  }
}
::v-deep .el-dialog__body {
  padding: 30px 20px !important;
  background: #003a47 !important;
  max-height: none !important;
  color: #fff !important;
  .el-input__inner {
    color: #ffffff !important;
    border-color: #57acc2 !important;
    background-color: transparent !important;
  }
  .el-table {
    max-height: none !important;
  }
}
::v-deep .el-dialog__footer {
  background: #003a47;
  border-color: #000 !important;
}
.list-wrapper {
  height: 500px;
}
</style>
